using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
    /// <summary>
    /// Controller class for Company
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CompanyController
    {
        // Preload our schema..
        Company thisSchemaLoad = new Company();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CompanyCollection FetchAll()
        {
            CompanyCollection coll = new CompanyCollection();
            Query qry = new Query(Company.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CompanyCollection FetchByID(object CompanyCode)
        {
            CompanyCollection coll = new CompanyCollection().Where("CompanyCode", CompanyCode).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CompanyCollection FetchByQuery(Query qry)
        {
            CompanyCollection coll = new CompanyCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object CompanyCode)
        {
            return (Company.Delete(CompanyCode) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object CompanyCode)
        {
            return (Company.Destroy(CompanyCode) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string CompanyName,string Logo,DateTime? ValidFrom,DateTime? ValidTo,int? Credits,bool UnlimitedCredits,bool UnlimitedCategories,double? PricePerSecond,int? NewsTemplateID,bool Active,DateTime DateAdded,DateTime DateModified,bool UnlimitedCommercialCategories)
	    {
		    Company item = new Company();
		    
            item.CompanyName = CompanyName;
            
            item.Logo = Logo;
            
            item.ValidFrom = ValidFrom;
            
            item.ValidTo = ValidTo;
            
            item.Credits = Credits;
            
            item.UnlimitedCredits = UnlimitedCredits;
            
            item.UnlimitedCategories = UnlimitedCategories;
            
            item.PricePerSecond = PricePerSecond;
            
            item.NewsTemplateID = NewsTemplateID;
            
            item.Active = Active;
            
            item.DateAdded = DateAdded;
            
            item.DateModified = DateModified;
            
            item.UnlimitedCommercialCategories = UnlimitedCommercialCategories;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int CompanyCode,string CompanyName,string Logo,DateTime? ValidFrom,DateTime? ValidTo,int? Credits,bool UnlimitedCredits,bool UnlimitedCategories,double? PricePerSecond,int? NewsTemplateID,bool Active,DateTime DateAdded,DateTime DateModified,bool UnlimitedCommercialCategories)
	    {
		    Company item = new Company();
		    
				item.CompanyCode = CompanyCode;
				
				item.CompanyName = CompanyName;
				
				item.Logo = Logo;
				
				item.ValidFrom = ValidFrom;
				
				item.ValidTo = ValidTo;
				
				item.Credits = Credits;
				
				item.UnlimitedCredits = UnlimitedCredits;
				
				item.UnlimitedCategories = UnlimitedCategories;
				
				item.PricePerSecond = PricePerSecond;
				
				item.NewsTemplateID = NewsTemplateID;
				
				item.Active = Active;
				
				item.DateAdded = DateAdded;
				
				item.DateModified = DateModified;
				
				item.UnlimitedCommercialCategories = UnlimitedCommercialCategories;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

